package com.LeeCode;

/**
 * 找出有效子序列的最大长度 I
 */

public class Code3201 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 1, 1, 2, 1, 2};
        System.out.println(new Code3201().maximumLength(nums));
    }

    public int maximumLength(int[] nums) {
        int[] count = new int[4];
        for (int num : nums) {
            if ((num & 1) == 0) { // 偶数
                count[0]++;
                count[2] += (count[2] & 1) == 0 ? 1 : 0;
                count[3] += (count[3] & 1) == 1 ? 1 : 0;

            } else { // 奇数
                count[1]++;
                count[3] += (count[3] & 1) == 0 ? 1 : 0;
                count[2] += (count[2] & 1) == 1 ? 1 : 0;
            }
        }
        int ans = 0;
        for (int num : count)
            ans = Math.max(ans, num);
        return ans;
    }
}
